package labox.innovation.gameserver.model;

import java.util.Arrays;

/**
 *	一个掉落模板
 */
public final class FuzeDropData {
	
	public static final int MAX_CHANCE = 1000000;

	/**
	 * 掉落的道具ID
	 */
	private int _itemId;

	/**
	 * 道具掉落的概率
	 */
	private int _chance;
	
	/**
	 * 掉落的道具数量
	 */
	private int _itemCount;

	private String _questID;

	private String[] _stateID;

	/**
	 * Returns the ID of the item dropped
	 * @return int
	 */
	public int getItemId() {
		return _itemId;
	}

	/**
	 * Sets the ID of the item dropped
	 * @param itemId : int designating the ID of the item
	 */
	public void setItemId(int itemId) {
		_itemId = itemId;
	}

	/**
	 * Returns the chance of having a drop
	 * @return int
	 */
	public int getChance() {
		return _chance;
	}

	/**
	 * Sets the chance of having the item for a drop
	 * @param chance : int designating the chance
	 */
	public void setChance(int chance) {
		_chance = chance;
	}

	public void setItemCount(int itemCount) {
		_itemCount = itemCount;
	}

	public int getItemCount() {
		return _itemCount;
	}

	/**
	 * Returns the stateID.
	 * @return String[]
	 */
	public String[] getStateIDs() {
		return _stateID;
	}

	/**
	 * Adds states of the dropped item
	 * @param list : String[]
	 */
	public void addStates(String[] list) {
		_stateID = list;
	}

	/**
	 * Returns the questID.
	 * @return String designating the ID of the quest
	 */
	public String getQuestID() {
		return _questID;
	}

	/**
	 * Sets the questID
	 * @param String designating the questID to set.
	 */
	public void setQuestID(String questID) {
		_questID = questID;
	}

	/**
	 * Returns if the dropped item is requested for a quest
	 * @return boolean
	 */
	public boolean isQuestDrop() {
		return _questID != null && _stateID != null;
	}

	/**
	 * Returns a report of the object
	 * @return String
	 */
	@Override
	public String toString() {
		String out = "ItemID: " + getItemId()  + " Chance: " + (getChance() / 10000.0) + "%";
		if (isQuestDrop()) {
			out += " QuestID: " + getQuestID() + " StateID's: " + Arrays.toString(getStateIDs());
		}

		return out;
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + _itemId;
		return result;
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof FuzeDropData))
			return false;
		final FuzeDropData other = (FuzeDropData) obj;
		if (_itemId != other._itemId)
			return false;
		return true;
	}
}
